<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/commons/global.jsp" %>
<style>
</style>

<div class="easyui-layout" data-options="fit:true,border:false">
    <div data-options="region:'center',border:false">
        <table id="cc"></table>  
    </div>
</div>
<script type="text/javascript">
    var editIndex;
    $(function(){
        var globalVal;
        var datas={};
        $.ajax({
            async:false,
            url: '${ctxPath}/process/queryComment?processInstanceId=${processInstanceId}',
            method:'get',
            dataType:'json',
            success:function(data){
                datas=data;
            }
        })
        $('#cc').datagrid({
            width:'100%',
            singleSelect:true,
            columns:[[
                {field:'taskId',title:'任务ID',width:80},
                {field:'taskName',title:'任务名称',width:100},
                {field:'userName',title:'评论人',width:100},
                {field:'time',title:'评论时间',width:100,
                    formatter:function(value){
                      return datetime2Str(value)
                    }
                },
                {field:'comment',title:'评论内容',width:300},

                {field:'print',title:'是否打印',width:80,
                    formatter:function(value){
                        if(value==1){
                            return "是";
                        }else{
                            return "否";
                        }
                    },
                    editor:{
                        type:'combobox',
                        options:{
                            valueField:'id',
                            textField:'name',
                            data:[{id:1,name:"是"},{id:0,name:"否"}],
                            required:true,
                            panelHeight: 'auto'
                        }
                    }
                },
                {field:'action',title:'操作',width:70,align:'center',
                    formatter:function(value,row,index){
                        if (row.editing){
                            var s = '<a href="#" onclick="saverow('+index+')">保存</a> ';
                            var c = '<a href="#" onclick="cancelrow('+index+')">取消</a>';
                            return s+c;
                        } else {
                            var e = '<a href="#" onclick="editrow('+index+')">编辑</a> ';
                            return e;
                        }
                    }
                }
            ]],
            onBeforeEdit:function(index,row){
                row.editing = true;
                $('#cc').datagrid('refreshRow', index);
                editcount++;
            },
            onAfterEdit:function(index,row){
                row.editing = false;
                $('#cc').datagrid('refreshRow', index);
                editcount--;
            },
            onCancelEdit:function(index,row){
                row.editing = false;
                $('#cc').datagrid('refreshRow', index);
                editcount--;
            }
        }).datagrid('loadData',datas).datagrid('acceptChanges');
    });
    var editcount = 0;
    function editrow(index){
        $('#cc').datagrid('beginEdit', index);
    }
    function deleterow(index){
        $.messager.confirm('确认','是否真的删除?',function(r){
            if (r){
                $('#cc').datagrid('deleteRow', index);
            }
        });
    }
    function saverow(index){
        editIndex=index;
        $('#cc').datagrid('endEdit', index);
        $("#cc").datagrid("selectRow",index);
        var row = $("#cc").datagrid("getSelected");

        $.ajax({
            type:"post",dataType:"json",
            url:"${ctxPath}/process/updatePrint",
            data:{id:row.id,print:row.print},
            success:function(data){
                if(data.success) {
                    showMsg(data.msg);
                    $('#cc').datagrid('reload');

                }else{
                    $.messager.alert("错误",data.msg,"error");
                }
            }
        });

    }
    function cancelrow(index){
        $('#cc').datagrid('cancelEdit', index);
    }

</script>
